package com.exercises;

import java.util.HashMap;
import java.util.Map;

public class Exercise446 {

    public static void main(String[] args) {
        System.out.println(numberOfArithmeticSlices(new int[]{0, 2000000000, -294967296}));
    }

    public static int numberOfArithmeticSlices(int[] nums) {
        int n = nums.length;
        Map<Long, Integer>[] dp = new HashMap[n];
        for (int i = 0; i < n; i++) {
            dp[i] = new HashMap<>();
        }
        int result = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                long sub = 1L * nums[i] - nums[j];
                int preResult = dp[j].getOrDefault(sub, 0);
                result += preResult;
                dp[i].put(sub, dp[i].getOrDefault(sub, 0) + preResult + 1);
            }
        }
        return result;

    }

}
